package flutterdemo.controller;

import flutterdemo.model.Message;
import flutterdemo.service.MessageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.IOException;
import java.util.List;

/**
 * 消息上传
 */
@RestController
@RequestMapping("/message")
@CrossOrigin
public class MessageController {
    @Autowired
    private MessageService messageService;

    @PostMapping("/uploadMessage")
    public String uploadMessage(
            @RequestBody Message message) throws IOException {
        messageService.uploadMessage(message.getMessageContent(), message.getImageUrlList(), message.getUserType());
        return "success";
    }

    @PostMapping("/deleteAllMessage")
    public String deleteAllMessage() throws IOException {
        messageService.deleteAllMessage();
        return "success";
    }

    @PostMapping("/queryAllMessage")
    public List<Message> queryAllMessage() throws IOException {
        return messageService.queryAllMessage();
    }
}
